package com.fhj.bookshop.controller;


import com.fhj.bookshop.common.R;
import com.fhj.bookshop.entity.Comments;
import com.fhj.bookshop.mapper.CommentsMapper;
import com.fhj.bookshop.service.ICommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.lang.reflect.Method;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fu
 * @since 2023-12-26
 */
@RestController
public class CommentsController {

    @Autowired
    CommentsMapper commentsMapper;

    @Autowired
    ICommentsService commentsService;


    @RequestMapping(value = "/addComments",method = RequestMethod.POST)
    public R addComments(@RequestBody Comments comments){
        commentsMapper.insert(comments);
        return R.ok("评论成功").setData(comments);
    }

    @RequestMapping(value ="/getComments/{proId}",method = RequestMethod.GET)
    public R getComments(@PathVariable Integer proId){
        List<Comments> commentsList=commentsService.getComments(proId);
        return R.ok("评论加载成功").setData(commentsList);
    }

}
